const {
  defineConfig
} = require('@vue/cli-service')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpack = require('webpack');
const path = require('path')
const cesiumSource = './node_modules/cesium/Source'

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  configureWebpack: {
    output: {
      sourcePrefix: ' ' // 让webpack 正确处理多行字符串配置 amd参数
    },
    amd: {
      toUrlUndefined: true // webpack在cesium中能友好的使用require
    },
    resolve: {
      extensions: ['.js', '.vue', '.json'],
      alias: {
        // 'cesium/Cesium': path.resolve(__dirname, cesiumSource), //别名
        'cesium': path.resolve(__dirname, cesiumSource), //别名
      }
    },
    plugins: [
      new CopyWebpackPlugin([{
        from: path.join(cesiumSource, 'Workers'),
        to: 'Workers'
      }]),
      new CopyWebpackPlugin([{
        from: path.join(cesiumSource, 'Assets'),
        to: 'Assets'
      }]),
      new CopyWebpackPlugin([{
        from: path.join(cesiumSource, 'Widgets'),
        to: 'Widgets'
      }]),
      new CopyWebpackPlugin([{
        from: path.join(cesiumSource, 'ThirdParty/Workers'),
        to: 'ThirdParty/Workers'
      }]),
      new webpack.DefinePlugin({
        CESIUM_BASE_URL: JSON.stringify('./')
      }),
      new NodePolyfillPlugin()
    ],
  },
  devServer: {
    host: '0.0.0.0',
    port: 9527,
    open: false,
    proxy: {
      
    }
  }
})